package com.company.vmvp.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.company.vmvp.R;
import com.company.vmvp.tools.AppTools;
import com.company.vmvp.tools.PermissionTools;
import com.company.vmvp.ui.main.entity.UserBean;
import com.dee.components.base.mvp.BasePresenter;
import com.dee.components.base.ui.FragmentBase;
import com.dee.components.widget.TitleView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 作者：kkan on 2017/01/30
 * 当前类注释:基类fragment
 */
public abstract class BaseFragment<T extends BasePresenter> extends FragmentBase<T> {
    @Nullable
    @BindView(R.id.toolbar_title_view)
    TitleView toolbarTitleView;
    @Nullable
    @BindView(R.id.toolbar_line)
    TextView toolbarLine;
    @Nullable
    @BindView(R.id.toolbar_title_ll)
    LinearLayout toolbarTitleLl;

    private Unbinder unbinder;
    public PermissionTools permissionTools;
    public UserBean userBean;

    @Override
    public void doBeforeContentView() {
        super.doBeforeContentView();
        permissionTools = new PermissionTools(this);
    }

    @Override
    public void doAfterContentView() {
        super.doAfterContentView();
        if (rootView != null) {
            unbinder = ButterKnife.bind(this, rootView);
        }

        upToolBarLeftGone();
        userBean = AppTools.getUserBean();

        immersive(toolbarTitleView, false);
    }

    public void upToolBarLeftGone(){
        if (toolbarTitleView != null) {
            toolbarTitleView.setLeftIconVisibility(false);
            toolbarTitleView.setLeftTextVisibility(false);
        }
        if (toolbarLine != null) {
            toolbarLine.setVisibility(View.GONE);
        }
    }

    public String getIntentString(String name){
        String data="";
        Bundle bundle = getArguments();
        if (bundle != null) {
            data = bundle.getString(name);
        }
        return data;
    }

    public void showTipDialog(CharSequence message){
        showTipDialog("系统提示",message,"确定","",true,null,null);
    }

    public void showTipDialog(CharSequence message, View.OnClickListener leftlistener){
        showTipDialog("系统提示",message,"确定","取消",true,leftlistener,null);
    }
    public void showTipDialog(String title, CharSequence message, View.OnClickListener leftlistener){
        showTipDialog(title,message,"确定","取消",true,leftlistener,null);
    }

    public void showTipDialog(String title, CharSequence message,String leftStr, View.OnClickListener leftlistener){
        showTipDialog(title,message,leftStr,"取消",true,leftlistener,null);
    }


    public void showTipDialog(String title,CharSequence message,String leftStr,String rightStr,boolean cancelableOutside,View.OnClickListener leftlistener,View.OnClickListener rightlistener){

        creatDialogBuilder()
                .setDialog_title(title)
                .setDialog_message(message)
                .setDialog_Left(leftStr)
                .setLeftlistener(leftlistener)
                .setDialog_Right(rightStr)
                .setRightlistener(rightlistener)
                .setCancelableOutside(cancelableOutside)
                .show();

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }


}
